package com.breakfast.fun.adapter.user;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.breakfast.fun.base.BaseListAdapter;
import com.breakfast.fun.data.entity.user.help.HelpData;
import com.breakfast.fun.ui.user.help.HelpContentActivity;
import com.breakfast.fun.R;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/9/9.
 */
public class UserHelpCenterAdapter extends BaseListAdapter<HelpData> {
    public UserHelpCenterAdapter(Context context, List<HelpData> list) {
        super(context, list);
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        final ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_help_center, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.tvHelpCenterItem.setText(getItem(i).getTitle());

        holder.rlHelpCenterItem.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(mContext, HelpContentActivity.class);
                intent.putExtra("url", getItem(i).getContent());
                mContext.startActivity(intent);
            }
        });

        return convertView;
    }

    static class ViewHolder {
        @Bind(R.id.tv_help_center_item)
        TextView tvHelpCenterItem;
        @Bind(R.id.rl_help_center_item)
        RelativeLayout rlHelpCenterItem;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
